<?php


namespace Yond\LaravelDomain\Console;

use Illuminate\Support\Str;
use Yond\LaravelDomain\Console\Traits\ParserTrait;

class AppMakeCommand extends Command
{
    use ParserTrait;

    public $signature = 'yond:domain:app {--app= : The name of app}';

    protected $description = 'Make a domain app';

    public function handle()
    {
        $app = ucfirst($this->optionOrAsk('app', 'Please the name of domain app to generated'));

        $appPath = app_path($app);

        if ($this->alreadyExists($appPath)) {
            return;
        }

        $this->ensureDirectoryExists($appPath);

        copy(__DIR__ . '/../../stubs/default/config.php', $appPath. '/config.php');

        $routeContent = $this->parseStubContent($this->getStub('routes.stub'), ['prefix' => Str::snake($app)]);
        $this->files->put($appPath.'/routes.php', $routeContent);

        $this->info($app . ' app created');
    }
}